﻿using HostAssistantCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HostAssistantBLL
{
    /// <summary>
    /// ftp
    /// </summary>
    public class ftpbll
    {
        #region 删除ftp
        /// <summary>
        /// 删除ftp
        /// </summary>
        public static void ftpdelete(string ftpname,string path)
        {
         
                
            //删除Ftp站点
                int iistouch = UtilFactory.IISTouch();
                if (iistouch == 2)
                {
                   
                         FtpUtil.DeleteFtp(ftpname);
                        //删除用户权限
                        AddSiteUtil addsiteUtil = new AddSiteUtil();
                        addsiteUtil.icaclsRemove(ftpname, path);
                       IISManager iismanager = new IISManager();
                        iismanager.flushFtps();

                   
                }
                else if (iistouch == 1)
                {
                  

                         FtpUtil.DeleteQFtp(ftpname);
                        //删除用户权限
                       AddSiteUtil addsiteUtil = new AddSiteUtil();
                        addsiteUtil.icaclsRemove(ftpname, path);
                IISManager iismanager = new IISManager();
                iismanager.flushFtps();

                  
                }
                else
                {
                   

                throw new Exception("IIS版本未知");

            }
          
         
        }



        #endregion

        #region 刷新列表
        /// <summary>
        /// 刷新列表
        /// </summary>
        public static void Reshftplist()
        {
               new  IISManager().   flushFtps();
        }
         


        #endregion

        #region ftp列表
        public static List<Ftpsite> GetsiteList(string Mdbname)
        { 
            Ftpsite SqlInfo = new Ftpsite();
            string sql = "  select * from Ftpsite where   1=1   ";
            List<Ftpsite> list = new List<Ftpsite>();
            if (!string.IsNullOrWhiteSpace(Mdbname))
            {
                SqlInfo.Name = "%" + Mdbname + "%";
                sql += "  and name like @name  ";
            }
           



            list = Data<Ftpsite>.GetInstance().GetModelList(sql, SqlInfo);
            return list==null? new List<Ftpsite>():list;
        }
        #endregion

        #region  获取 ftp
        public static Ftpsite GetFtpsite(string id)
        {
            string sql = "    id=@ID  ";
            Ftpsite SqlInfo = new Ftpsite();
            SqlInfo.ID = ZConvert.StrToInt(id);
            return Data<Ftpsite>.GetInstance().GetModel("Ftpsite", sql, SqlInfo);
        }
        #endregion
    }
}
